Thumb

What is for loop?

1/8/2020 5:28:27 AM

Loop is a mechanism to count the array or list value get or set the condition. Loop is very important for C# and other programming. For loop is divide the three part are initialization, conditional and increment/decrement. The loop is running until the condition are false. Now given bellow the example code and explain the code:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Reflection;
using testForClass1;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace testFor
{
    public class Program
    {
        static void Main(string[] args)
        {
            String[] Days = new string[7] { "Sun", "Mon", "Tue", "Wed","Thu","Fri","Sa" };
            for (int i = 0; i < Days.Length; i++)
            {
                Console.WriteLine(Days[i]);
            }
            int[] Num = new int[] { 100, 200, 300, 400, 500, 600 };

            for (int i = 0; i < Num.Length; i++)
            {
                Console.WriteLine(Num[i]);
            }
            Console.Read();
        }
    }
}

In this code we write two array one is int and string. String array we set the size but int array we can’ set the size. Now first initialize the value into array then we print the array value using the for loop.